package com.mediacloud.app.newsmodule.activity

import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.mediacloud.app.assembly.util.DateParse
import com.mediacloud.app.model.news.ProgramListItem
import com.mediacloud.app.newsmodule.R
import com.mediacloud.app.newsmodule.activity.microlive.BaseRecyclerAdapterX

class ChatLiveProgramListAdapter(context: Context?,private val mainColor:Int) : BaseRecyclerAdapterX<ProgramListItem>(context) {
    var startLong = 0L
    var endLong = 0L

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): androidx.recyclerview.widget.RecyclerView.ViewHolder {
        return ProgramDateHolder(LayoutInflater.from(getContext()).inflate(R.layout.aappfactory_itemprogram_chat, parent, false))
    }

    override fun onBindViewHolder(holder: androidx.recyclerview.widget.RecyclerView.ViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        if (holder is ProgramDateHolder) {
            holder.update(getItem(position))
        }
    }

    inner class ProgramDateHolder(itemView: View) : androidx.recyclerview.widget.RecyclerView.ViewHolder(itemView) {
        private val programName: TextView = itemView.findViewById(R.id.programName)
        private val time: TextView = itemView.findViewById(R.id.time)
        private  var unPlayColor =Color.parseColor("#ff333333")
        fun update(dateItem: ProgramListItem) {
            programName.text = dateItem.name
            val date = DateParse.getDate(0, 0, 0, 0, dateItem.starttime, null, "HH:mm")
            time.text = "播出时间：" + date!!
            val startDate = DateParse.parseDate(dateItem.starttime, null).time
            val endDate = DateParse.parseDate(dateItem.endtime, null).time

            if (startLong == 0L) {
                var  currentTime =System.currentTimeMillis()
                if(currentTime in startDate..endDate){
                    programName.setTextColor(mainColor)
                }else{
                    programName.setTextColor(unPlayColor)
                }
            } else {
                if (startLong >= startDate && endLong <= endDate) {
                    programName.setTextColor(mainColor)
                } else {
                    programName.setTextColor(unPlayColor)
                }
            }
        }
    }


}